﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace GUI
{
    public partial class Form2 : Form
    {
        public static string ins;
        public static int quantity;
        public static double price;
        public static string orderType;


        public static bool button1Clicked;
        public static bool button2Clicked;

        


        public Form2()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            //Application.Exit();
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1Clicked = true;
            ins = this.Instrument.Text;
            orderType = this.OrderType.Text;
            //MessageBox.Show(s);
            //Form3 confirm = new Form3();
            //this.Hide();
            //confirm.Show();
            price = double.Parse(this.Price.Text);
            quantity = int.Parse(this.Quantity.Text);

            if (price > 0.0 && quantity > 0)
            {

                if (MessageBox.Show("Trader " + Form1.traderID + " bid " + quantity + " " + ins + " at a price of $" + price, "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    //Form3 tradeOutput = new Form3();
                    //this.Hide();
                    string trader = Form1.traderID;
                    TradingClient traderCli = new TradingClient(trader);
                    traderCli.Start();
                    //MessageBox.Show("$$$$$$$$$$$$");
                    //tradeOutput.Show();
                }
            }



        }

        private void button2_Click(object sender, EventArgs e)
        {
            button2Clicked = true;
            ins = this.Instrument.Text;
            orderType = this.OrderType.Text;
            price = double.Parse(this.Price.Text);
            quantity = int.Parse(this.Quantity.Text);

            if (price > 0.0 && quantity > 0)
            {
                if (MessageBox.Show("Trader " + Form1.traderID + " offer " + quantity + " " + ins + " at a price of $" + price, "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    //Form3 tradeOutput = new Form3();
                    //this.Hide();
                    string trader = Form1.traderID;
                    TradingClient traderCli = new TradingClient(trader);
                    traderCli.Start();
                    //tradeOutput.Show();
                }
            }

        }

        private void Quantity_Leave(object sender, EventArgs e)
        {
            FillTotal();
        }

        private void Price_Leave(object sender, EventArgs e)
        {
            FillTotal();
        }

        private void FillTotal()
        {
            try
            {
                double price = double.Parse(this.Price.Text);
                int quantity = int.Parse(this.Quantity.Text);

                this.Total.Text = (price * quantity).ToString();
            }
            catch (Exception)
            {
                //throw;
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

        }




    }
}